package com.siblings.loan.ui.steps.adapter

import android.graphics.Color
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView
import com.siblings.lib_baseadapter.SIBRecyclerViewAdapter
import com.siblings.lib_baseadapter.SIBViewHolderHelper
import com.siblings.loan.R
import org.json.JSONObject

/**
 * Siblings
 * @Author wwdeng
 * @CreateTime: 2024/7/11 10:43
 * @Annotation：流程 - Ocr 适配器
 */
class SibStepOcrTypeAdapter(recyclerView: RecyclerView?) : SIBRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_step_ocr_type) {

    override fun setItemChildListener(helper: SIBViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout)
    }

    override fun fillData(helper: SIBViewHolderHelper, position: Int, model: JSONObject) {
        val itemLayout = helper.getView<LinearLayout>(R.id.itemLayout)
        val imgOcrType = helper.getImageView(R.id.imgOcrType)
        val textOcrType = helper.getTextView(R.id.textOcrType)
        textOcrType.text = model.optString("ocrTitle")
        val imgSelect = helper.getImageView(R.id.imgSelect)

        val isSelect = model.optBoolean("isSelect",false)
        when (isSelect){
            true -> {
                itemLayout.setBackgroundResource(R.drawable.sib_step_ocr_type_select)
                imgOcrType.setImageResource(model.optInt("imgSelect"))
                textOcrType.setTextColor(Color.parseColor("#FF4DB673"))
                imgSelect.setImageResource(R.mipmap.pic_step_ocr_type_select)
            }
            else -> {
                itemLayout.setBackgroundResource(R.drawable.sib_radius_frame_ff999999_12)
                imgOcrType.setImageResource(model.optInt("imgNormal"))
                textOcrType.setTextColor(Color.parseColor("#FF999999"))
                imgSelect.setImageResource(R.mipmap.pic_step_ocr_type_normal)
            }
        }
    }
}